home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / dkbuts.zip / DUMP2MTV.C < prev    next >
C/C++ Source or Header  |  1991-05-16  |  2KB  |  94 lines

  1. /*
  2.  * Dump2MTV.C - Converts DKB/QRT Dump 24-bit output file to MTV/Rayshade format
  3.  *
  4.  * Written by Ville Saari
  5.  *
  6.  * Copyright (c) 1991 Ferry Island Pixelboys.
  7.  * All rights reserved.
  8.  *
  9.  * Created 27-Dec-90
  10.  * Updated 31-jan-90
  11.  *
  12.  * Updated 26-Apr-91 V. 1.10 - Aaron A. Collins - made somewhat more portable,
  13.  * and made the program read and write files instead of stdin and stdout.
  14.  */
  15.  
  16. #include "stdio.h"
  17. #include "stdlib.h"
  18.  
  19. #define BUFSIZE 32768L
  20.  
  21. FILE *infile, *outfile;
  22.  
  23. void error(char *text, int code)
  24.    {
  25.    if(code) fputs("Dump2MTV: ", stderr);
  26.    fputs(text, stderr);
  27.    if (infile != NULL)
  28.       fclose(infile);
  29.    if (outfile != NULL)
  30.       {
  31.       fflush(outfile);
  32.       fclose(outfile);
  33.       }
  34.    exit(code);
  35.    }
  36.  
  37. void main(ac, arg)
  38. int ac;
  39. char *arg[];
  40.    {
  41.    char *buffer;
  42.    long bufptr, width, height, f, n;
  43.    char *c;
  44.  
  45.    fputs(
  46.          "\033[33;1mDUMP2MTV\033[0m V1.10 by Ville Saari.\n"
  47.          "Copyright (c) 1990 Ferry Island Pixelboys.\n"
  48.          "Freeware.\n\n", stderr);
  49.  
  50.    if (ac != 3)
  51.       error("Usage: Dump2MTV inputfile outputfile\n", 0);
  52.   
  53.    if((infile = fopen(arg[1], "rb")) == NULL)
  54.        error("Can't open input file.\n", 1);
  55.  
  56.    if((outfile = fopen(arg[2], "wb")) == NULL)
  57.        error("Can't create output file.\n", 1);
  58.  
  59.    if(!(buffer=malloc((unsigned int)BUFSIZE)))
  60.       error("Can't allocate memory for buffer.\n", 103);
  61.  
  62.    if(!fread(buffer, 4, 1, infile))
  63.       error("Can't read DKB/QRT Dump header.\n", 20);
  64.  
  65.    fprintf(stderr,
  66.       "Picture size: %d x %d.\n"
  67.       "Processing line      ",
  68.       width=(unsigned char)buffer[0]|((unsigned char)buffer[1]<<8),
  69.       height=(unsigned char)buffer[2]|((unsigned char)buffer[3]<<8));
  70.  
  71.    fprintf(outfile, "%d %d\n", width, height);
  72.    bufptr=0;
  73.  
  74.    for(f=0; f<height; f++)
  75.       {
  76.       fprintf(stderr, "\033[5D%-5d", f);
  77.       
  78.       if(((unsigned char)fgetc(infile)|((unsigned char)fgetc(infile)<<8))!=(int)f)
  79.          error("DKB/QRT Dump file incomplete.\n", 20);
  80.  
  81.       for(n=0, c=buffer+bufptr; n<width; n++, c+=3) *c=(char)fgetc(infile);
  82.       for(n=0, c=buffer+bufptr+1; n<width; n++, c+=3) *c=(char)fgetc(infile);
  83.       for(n=0, c=buffer+bufptr+2; n<width; n++, c+=3) *c=(char)fgetc(infile);
  84.  
  85.       if((bufptr+=3*width)+3*width>BUFSIZE || f>=height-1)
  86.          {
  87.          if(!fwrite(buffer, (unsigned int)bufptr, 1, outfile))
  88.             error("Error in writing MTV/Rayshade file.\n", 20);
  89.          bufptr=0;
  90.          }
  91.       }
  92.    fputs("\n", stderr);
  93.    }
  94.